<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    * {
        margin: 0;
        padding: 0;
    }

    .box {
        position: relative;
        width: 600px;
        height: 200px;
        border: 1px red solid;
        overflow: hidden;
        margin: 30px auto;
    }

    .box>ul {
        position: absolute;
        left: 0;
        top: 0;
        width: 300%;
        height: 100%;
        list-style: none;
    }

    .box>ul>li {
        float: left;
    }

    .box>ul>li>img {
        /* 去除垂直方向空隙 */
        vertical-align: top;
    }
</style>
<script>
    window.onload = function () {
        function $(selecter) {
            //找参数封装
            return document.querySelector(selecter)
            //调用最后在返回出来
        }
        var moveVal = 0
        var timer = null
        function fn() {
            moveVal -= 3
            if (moveVal <= -4 * 300) {
                moveVal = 0
            }
            $('ul').style.left = moveVal + 'px'
        }
        timer = setInterval(fn, 30)

        //鼠标放到大盒子上，动画停止
        $('.box').onmouseover = function () {
            clearInterval(timer)
        }
        // 鼠标离开大盒子，开启定时器
        $('.box').onmouseout = function () {
            timer = setInterval(fn, 30)
        }

    }
    
</script>

<body>
    <div class="box">
        <ul>
            <li><img src="./imgs/01.jpg" alt=""></li>
            <li><img src="./imgs/02.jpg" alt=""></li>
            <li><img src="./imgs/03.jpg" alt=""></li>
            <li><img src="./imgs/04.jpg" alt=""></li>
            
            <li><img src="./imgs/01.jpg" alt=""></li>
            <li><img src="./imgs/02.jpg" alt=""></li>
        </ul>
    </div>
</body>

</html>